package bgw

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
)

func GeneratePasswordDigest(nonce, created, secret string) string {
	hash := sha256.Sum256([]byte(nonce + created + secret))
	return base64.StdEncoding.EncodeToString(hash[:])
}

func GenerateBodySign(body, appCode, appSecret, requestId string) string {
	key := appCode + "&" + appSecret
	if requestId != "" {
		key += "&" + requestId
	}
	h := hmac.New(sha256.New, []byte(key))
	h.Write([]byte(body))
	return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
